home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDRemaining.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.2 KB  |  111 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDRemaining - An XFCN to report remaining time on disc
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDRemaining.c
  11.     link -sn Main=CDRemaining -sn STDIO=CDRemaining ∂
  12.          -sn INTENV=CDRemaining -rt XFCN=42 ∂
  13.          -m CDRemaining CDRemaining.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    ReadQ(short, long *, long *, long *, long *);
  28. OSErr    ThisDisc(short, long *, long *, long *);
  29. void    TimeDiff(long *, long *, long *, long, long, long, long, long, long);
  30. OSErr    NextTrack(long, long, long *, long *, long *);
  31.  
  32. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  33.  
  34.  
  35. /************************************************************************
  36.  *
  37.  *  Function:        CDRemaining
  38.  *
  39.  *  Purpose:        return the remaining time on this disc.
  40.  *
  41.  *  Returns:        either 0, or an error
  42.  *                    if it's a negative number, it's an error
  43.  *
  44.  *  Side Effects:
  45.  *
  46.  *  Description:    We need no parameter:
  47.  *                    Get the ioRefNum that we got from previously calling
  48.  *                    CDOpen() by accessing the famous global
  49.  *                    call the driver to find the current position.  Call
  50.  *                    the driver to get the lead-out time (end of disc time)
  51.  *                    Subtract the two and return the result.
  52.  *
  53.  ************************************************************************/
  54. pascal void
  55. CDRemaining(paramPtr)
  56. XCmdBlockPtr    paramPtr;
  57. {
  58.     Str31    returnString;
  59.     OSErr    result;
  60.     short    ioRefNum;
  61.     Handle    refHandle;
  62.     long    Remaining[4];    /* minute, second, block */
  63.     long    currentMinute, currentSecond, currentBlock;
  64.     long    startMinute, startSecond, startBlock;
  65.     
  66.     /* Must be no parameter */
  67.     if ((paramPtr->paramCount) != 0)
  68.     {
  69.         /* Report error in parameters by returning -1 */
  70.         NumToStr(paramPtr, (long) -1, &returnString);
  71.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  72.         return;
  73.     }
  74.     
  75.     /* Get the global ioRefNum and convert it. */
  76.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  77.     ioRefNum = atoi(*(refHandle));
  78.     DisposHandle(refHandle);
  79.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  80.     
  81.     
  82.     result = ReadQ(ioRefNum, &Remaining[0], ¤tMinute, ¤tSecond, ¤tBlock);
  83.     
  84.     if (result == noErr)
  85.         result = DiscTime(ioRefNum, &startMinute, &startSecond, &startBlock);
  86.         
  87.     if (result == noErr)
  88.     {
  89.         TimeDiff(&Remaining[1], &Remaining[2], &Remaining[3],
  90.                  startMinute, startSecond, startBlock,
  91.                  currentMinute, currentSecond, currentBlock);
  92.     }
  93.  
  94.     if (result == noErr)
  95.     {
  96.         /* convert each value to a string, concatenate, & return. */
  97.         FormatString(&returnString, Remaining, 4);
  98.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  99.     }
  100.     else
  101.     {
  102.         /* We got an error. Convert result to string & return it as error */
  103.         NumToStr(paramPtr, (long) result, &returnString);
  104.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  105.     }
  106. }
  107.  
  108.  
  109. /* C routines for HyperCard callbacks */
  110. #include <XCmdGlue.inc.c>
  111.